package cn.edu.suda.catalina.dataupdate.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * Created by admin on 2017/6/7.
 */
public class FileInputUtil {
    /**
     * 文件夹是否存在
     * @param filePath
     * @return
     */
    public static boolean mkdirs(String filePath) {
        File directory = new File(filePath);
        if (!directory.exists()) {
            if (!directory.mkdirs()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 上传java文件
     * @param filePath
     * @param file
     * @return
     */
    public static boolean javaFileInput(String filePath, MultipartFile file) {
        try {
            file.transferTo(new File(filePath + File.separator + file.getOriginalFilename() + ".bak"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }

    /**
     * 上传data文件
     * @param filePath
     * @param file
     * @return
     */
    public static boolean dataFileInput(String filePath, MultipartFile file) {
        try {
            file.transferTo(new File(filePath + File.separator + file.getOriginalFilename()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }
}
